<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.beaut.project.util.FlowUtility" %>
<%@ include file="/public/header.jsp"%>
<%
    String callback = request.getParameter("callback");
	String isShow = request.getParameter("isShow") == null ? "" : request.getParameter("isShow");
    String xm_id = request.getParameter("xm_id") == null ? "" : request.getParameter("xm_id");
	String xm_code = request.getParameter("xm_code") == null ? "" : request.getParameter("xm_code");
	String xm_name = request.getParameter("xm_name") == null ? "" : request.getParameter("xm_name");
    boolean isAdd = "".equals(xm_id);
    int flag = 0;
    if(!isAdd){
    	flag = 1;
    }

%>
<html>
	<head>
		<title>履约管理</title>
	</head>
	<script type="text/javascript">
		$(function(){
			$("#searchValue").keypress(function(e) { 
		    	// 回车键事件 
		     	if(e.which == 13) { 
		     		 doSearch();
		       	} 
		   	}); 
			$("#dept_id").combotree({
				url:'<%=contextPath %>/springMVC/group/listDepartment',
				method:'POST',
				animate:true,
				lines:true,
				onChange:function(){
					doSearch();
				}
			});
			$("#table").datagrid({
				title:"履约管理",
				iconCls:'icon-edit',
				loadMsg:'正在加载数据，请稍后......',
				url:'<%=contextPath %>/springMVC/xm/listPageLy?xm_id=<%=xm_id%>',
				rownumbers:true,
				fitColumns:true,
				nowrap:false,
				idField:'id',
				frozenColumns:[[
					{field:'ck',checkbox:true},		
				    {title:'主键',field:'id',hidden:true},
				]],
				columns:[[
					{title:'周报时间',field:'record_time',width:200,align:'center',sortable:true},
					{title:'周报记录人',field:'recorder',width:100,align:'center'},
					{title:'项目编号',field:'xm_code',width:100,align:'center'},
					{title:'项目名称',field:'xm_name',width:200,align:'center'},
					{title:'总进度(%)',field:'xm_progress_rate',width:100,align:'center'},
					//{title:'项目问题描述',field:'problem_desc',width:300,align:'center'},
					{title:'项目状态',field:'xm_status',width:100,align:'center',formatter:function(value,row,index){
						if(value == 1){
							return "正常项目";
						}
						if(value == 2){
							return "超期项目";
						}
						return "";
					}},
					{title:'项目基础信息',field:'xm_base_info',width:100,align:'center',formatter:function(value,rowData,rowIndex){
					    var str="";
						str+= "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-details' title='项目信息' onclick=\"javascript:viewData('"+rowData.xm_id+"');\"/>";
						return str;
					}},
					{title:'详情操作',field:'more',width:200,align:'center',formatter:function(value,rowData,rowIndex){
						var str="";
						str+= "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-modify' title='编辑' onclick=\"javascript:addOrEditLy(1,'"+rowData.id+"');\"/> &nbsp;&nbsp;";
						str+= "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-details' title='查看详情' onclick=\"javascript:addOrEditLy(3,'"+rowData.id+"');\"/> &nbsp;&nbsp;";
						return str;
					}}
				]],
				toolbar:"#tb",
				pageSize:10,
				pageList : [10,50,100],  
				pagination:true,
				onLoadSuccess:function(rtJson){
					if(rtJson.rtState== '1')
					{
						$.messager.alert('提示',rtJson.rtMsrg);
					}
				}
			});
		});

		
		function deleteLy(ly_id){
			var rows=$('#table').datagrid('getSelections');
			$.messager.confirm('确认','您确认删除该记录信息？',function(msg){
				if(msg){
					$.ajax({
						type:'POST',
						url:"<%=contextPath %>/springMVC/gd/deleteGd",
						data:"ly_id="+ly_id,
						success:function(rtJson){
							if(rtJson.rtState == '0'){
								table_reload(rows.length);
							}
							else{
								warningInfo(rtJson.rtMsrg);
							}
						}
					});
				}
			});
		}

		function  viewData(id){
			openDialogResize("<%=contextPath %>/springViews/xm/viewXm.jsp?xm_id="+id+"&callback=rtCallBack",1000, 800);
	
		}
		function rtCallBack(){
			$('#table').datagrid('reload');
		}
		function doSearch()
		{
			var start_time=$('#start_time').datebox('getValue');  
			var end_time=$('#end_time').datebox('getValue');  
			var searchValue = $('#searchValue').val();
			var dept_id = $("#dept_id").combotree('getValue');
			$('#table').datagrid('load',{
				searchValue:searchValue,
				start_time:start_time,
				dept_id : dept_id,
				end_time:end_time
				
			});
		}
        function deleteRows(){
			var rows=$('#table').datagrid('getSelections');
			var deleteVar="";
			if(rows.length==0)
			{
				$.messager.alert('提示','选中要删除的记录');  
				return ;
			}
			for(var i=0;i<rows.length;i++)
			{
				if(i==(rows.length-1))
				{
					deleteVar+=rows[i].id;
				}else
				{
					deleteVar+=rows[i].id+",";
				}
			}
			$.messager.confirm('确认','您确认删除该记录信息？',function(msg){
				if(msg){
					$.ajax({
						type:'POST',
						url:"<%=contextPath %>/springMVC/xm/deleteXMLy",
						data:"ids="+deleteVar,
						dataType:"json",
						success:function(rtJson){
							if(rtJson.rtState == '0'){
								table_reload(rows.length);
							}
							else{
								warningInfo(rtJson.rtMsrg);
							}
						}
					});
				}
			});
		}

		function addOrEditLy(type,id){
			if(type==0){
				openDialogResize("<%=contextPath %>/springViews/xm/addOrEditLy.jsp?callback=rtCallBack",1000, 800);
			}else if(type==1){
				openDialogResize("<%=contextPath %>/springViews/xm/addOrEditLy.jsp?callback=rtCallBack&id="+id,1000, 800);
			}else{
				openDialogResize("<%=contextPath %>/springViews/xm/addOrEditLy.jsp?isShow=1&callback=rtCallBack&id="+id,1000, 800);
		}
		}
	</script>
	<body style="height: 97%">
		<div id="table" data-options="fit:true" ></div>
		<div id="tb" style="padding:3px;height:auto">
			<div style="float:left;">
				<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="deleteRows();">删除</a>
				<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="addOrEditLy(0);">新增</a>
			</div>
			<div align="right">
				所属部门：<input  id="dept_id" name="dept_id" class="easyui-combotree">&nbsp;&nbsp; 
				开始时间：<input id="start_time" name="start_time" class="easyui-datebox" />&nbsp;&nbsp;&nbsp;结束时间：<input id="end_time" name="end_time" class="easyui-datebox" />
				项目编号/名称：<input id="searchValue" name="searchValue" style="width:150px" title="项目编号/名称" placeholder="项目编号/名称 "  />&nbsp;&nbsp; 
				<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch();"></a>
			</div>
		</div>
	</body>
</html>
